/*  
* Copyright (c) 2010, James Daniello
* This project is licensed under the 'New BSD' license.
* The full text of the license can be found in the root
* directory under the filename "LICENSE"
*/
package src.gui;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.text.NumberFormat;
import javax.swing.JFormattedTextField;
import java.awt.Container;
import java.awt.Color;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.BorderFactory;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.BorderLayout;

public class PICAIUClientGUIResetPass implements PICAIUGUI{

  //The various gui components.
  private Container frame;       //<-- the main panel container
  private JPanel content;
  private PICAIUClientGUI parent;
  
  private JTextField email;
  private JButton recover, cancel;
  private JLabel status;
  
  
  /**
  * Creates the gui component for when adding a server
  */
  public PICAIUClientGUIResetPass(Container frameIn, PICAIUClientGUI parentIn){
    frame = frameIn;
    parent = parentIn;
    initGUI();
  }
  
  
  /**
  * creates the gui components
  */
  public void initGUI(){
  
    content = new JPanel();
    
    JPanel padding1 = new JPanel();
    padding1.setSize(750,55);
    padding1.setPreferredSize(new java.awt.Dimension(750,55));
    padding1.setMaximumSize(new java.awt.Dimension(750,55));
    padding1.setMinimumSize(new java.awt.Dimension(750,55));
    content.add(padding1);
    
    JLabel logo = new JLabel("                         Recover Info/Reset Password                      ");
    Font f = new Font("Dialog", Font.PLAIN, 32);
    logo.setFont(f);
    content.add(logo);
    
    JPanel padding2 = new JPanel();
    padding2.setSize(750,45);
    padding2.setPreferredSize(new java.awt.Dimension(750,45));
    padding2.setMaximumSize(new java.awt.Dimension(750,45));
    padding2.setMinimumSize(new java.awt.Dimension(750,45));
    content.add(padding2);
    
    
    email = new JTextField();
    email.setColumns(25);
    content.add(new JLabel("                                                           "));
    content.add(new JLabel("         Email: "));
    content.add(email);
    content.add(new JLabel("                                                           "));
    content.add(new JLabel("                                                                    "));
    status = new JLabel("                                                    ");
    status.setForeground(Color.red);
    content.add(status);
    recover = new JButton("Recover");
    recover.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent evt){
        if(!email.getText().equals("")){
          recover.setEnabled(false);
          cancel.setEnabled(false);
          parent.getClient().sendDataToServer("RCVR#"+email.getText());
        }
      }
    });
    cancel = new JButton("Cancel");
    cancel.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent evt){
        parent.setGUI("login old");
      }
    });
    content.add(recover);
    content.add(cancel);
    content.add(new JLabel("                                                           "));
    content.add(new JLabel("                                         "));
  }
  
  
  /**
  * Indicates that a recover of username failed
  */
  public void recoverFailed(String error){
    recover.setEnabled(true);
    cancel.setEnabled(true);
    status.setText(error);
  }
  
  /**
  * This method switches the clients main container to this GUI's graphics.
  */
  @Override
  public void setAsGUI(){
    frame.removeAll();
    frame.add(content,BorderLayout.CENTER);
    email.requestFocusInWindow();
    frame.validate();
  
  }

  /**
  * This sets the colors of all the components affected by the color scheme to that of the current 
  * colors for the GUI
  */
  @Override
  public void setColors(PICAIUGUIScheme colorScheme){
    
    Color colorBG01=colorScheme.getBG01();
    Color colorBG02=colorScheme.getBG02();
    Color colorFG01=colorScheme.getFG01();
    Color colorBorder01=colorScheme.getBorder01();
  
  }

}